package com.handydata.antifraud.rule.funcs;

import com.handydata.antifraud.to.RiskInputTO;
import com.handydata.antifraud.to.RiskMiddleTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 计算家庭住址(省市区县)与手机Gps和百度地图经纬度
 */
@Component
public class CalcHomeAddrBetweenGpsAndBdMap extends CalcDistanceByLatAndLng {
    private static final Logger logger = LoggerFactory.getLogger(CalcHomeAddrBetweenGpsAndBdMap.class);
    @Override
    public void doCalc(RiskInputTO riskInputTO, RiskMiddleTO riskMiddleTO) {
        logger.info("{}开始计算住址(省市区县)与手机Gps和百度地图经纬度 getHomeCityGps{} latAndLngGps{} latAndLngBdMap{}",
                RULE_CALC_TEXT,riskInputTO.getHomeCityGps(),riskInputTO.getLongitudeAndLatitude(),riskInputTO.getBdLongitudeAndLatitude());
        double[] latAndLngHomeCity = getLatAndLng(riskInputTO.getHomeCityGps());
        double[] latAndLngGps = getLatAndLng(riskInputTO.getLongitudeAndLatitude());
        double[] latAndLngBdMap = getLatAndLng(riskInputTO.getBdLongitudeAndLatitude());

        double homePhoneAddressDis = getDistance(latAndLngHomeCity[0], latAndLngGps[0], latAndLngHomeCity[1], latAndLngGps[1]);
        double homeBdMapAddressDis = getDistance(latAndLngHomeCity[0], latAndLngBdMap[0], latAndLngHomeCity[1], latAndLngBdMap[1]);

        riskMiddleTO.setHomePhoneAddressDis(homePhoneAddressDis);
        riskMiddleTO.setHomeBdMapAddressDis(homeBdMapAddressDis);
        logger.info("{}结束计算住址(省市区县)与手机Gps和百度地图经纬度 homePhoneAddressDis{} homePhoneAddressDis{}", RULE_CALC_TEXT,homePhoneAddressDis,homePhoneAddressDis);
    }

    @Override
    protected String map(String gps) {
        return gps.replace("wgLat","latitude")
                .replace("wgLon", "longtitude");
    }

}
